package test;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import junit.framework.Assert;

import models.Deliverable;
import models.Milestone;
import models.Person;
import models.Project;
import models.Publication;

public class Factories {
	
// PERSON DATA
	
	private static Person creator = new Person("Ignacio", "Finoli", "4031458", "514 966 08181", "Student", Person.Sex.Male, "");
	
	// PUBLICATION DATA
	
	private static int publicationID = 1;
	private static Date publicationCreationDate = new Date(2009, 07, 10);
	private static Person publicationCreator = creator;
	private static String publicationTitle = "Test";
	private static String publicationLocation = "Montreal, QC";
	private static Date publicationDate = new Date(2009, 07, 10);
	private static ArrayList<Person> publicationAuthors = createActors();
	private static String publicationDescription ="";
	
	// DELIVERABLES DATA
	
	private static int deliverable_id = 1;
	private static int deliverableproject_id = 1;	
	private static Date deliverablecreationDate = new Date(2009, 07, 10);	
	private static Person deliverablecreator = creator;
	private static Date deliverablelastUpdate = new Date(2009,07,10);	
	private static Person deliverablelastUpdateBy = creator;
	private static String deliverabletitle = "Test";	
	private static int deliverableNumber = 1;	
	private static Person deliverableactor = creator;	
	private static Deliverable.Status deliverablestatus = Deliverable.Status.Complete;
	private static String deiverableadditionalNotes = "";
	
static // MILESTONE DATA 
	
	Milestone mile;
	private static int milestoneID = 1;
	private static Date milestoneCreationDate = new Date(2009, 07, 10); 
	private static Person milestoneCreator = creator;
	private static String milestonetitle = "Test";
	private static int milestoneNumber = 1;
	private static Date milestoneProjectedCompletion = new Date(2009, 8, 19);
	private static Date milestoneCompletionDate = new Date(2009, 8, 19);
	private static models.Milestone.Status milestatus = Milestone.Status.Incomplete;
	private static ArrayList<Deliverable> milestonedeliverables = createDeliverables();
	private static String milestoneAditionalNotes = "";
	
	// PROJECT DATA
	
	private static int Project_ID = 1;
	private static String Project_Name = "Comp354";
	private static String Project_Description = "Group Project";
	private static String Project_Creator_Name = "Greg Buttler";
	private static int Project_number_milestones = 10;
	private static int Project_number_deliverables = 10;
	private static int currentMilestonesCompleted = 0;
	private static int currentDeliverablesCompleted = 0;
	private float totalCompletionRate = 0;
	private static Date expectedCompletionDate = new Date(2009, 8, 19);
	private static Date finalCompletionDate = new Date(2009, 8, 19);
	private static ArrayList<Person> actors = createActors();
	private static ArrayList<Milestone> milestones = createMilestones();
	private static ArrayList<Publication> publications = createPublications();
	private static ArrayList<Deliverable> deliverables = createDeliverables();
	private static Project.Status status = Project.Status.Complete;
	private String additionalNotes = "";
	
	
	
	
	
	private static Project project = createProject();
	
	
	// Todo: must generate a random list of actors
	
	private static ArrayList<Person >createActors()
	{
		ArrayList<Person> list = new ArrayList<Person>(3);
		
		
		list.add(creator);
		list.add(creator);
		list.add(creator);
		
		
		
		return list;
	}
	
	// Todo: must generate a list of milestones
	
	private static ArrayList<Milestone> createMilestones()
	{
		ArrayList<Milestone> list = new ArrayList<Milestone>(3);
		mile = new Milestone(milestoneID, milestoneCreationDate, milestoneCreator, milestonetitle, milestoneNumber, 
				milestoneProjectedCompletion, milestoneCompletionDate, milestatus, milestonedeliverables, milestoneAditionalNotes);
		
		list.add(mile);
		list.add(mile);
		list.add(mile);
		
		
		return list;
	}
	
	// Todo must generate a list of publications
	
	private static ArrayList<Publication> createPublications()
	{
		ArrayList<Publication> list = new ArrayList<Publication>(3);
		Publication pub = new Publication(publicationID, 
											publicationCreationDate, 
											publicationCreator, 
											publicationTitle,
											publicationLocation, 
											publicationDate, 
											publicationAuthors, 
											publicationDescription);
		list.add(pub);
		list.add(pub);
		list.add(pub);
		
		
		
		return list;
	}
	
	// todo must generate a list of deliverables
	
	private static ArrayList<Deliverable> createDeliverables()
	{
		ArrayList<Deliverable> list = new ArrayList<Deliverable>(3);
		Deliverable deliv = new Deliverable(	deliverable_id, new Project(), deliverablecreationDate, 
												deliverablecreator, deliverablelastUpdate, 
												deliverablelastUpdateBy, deliverabletitle, deliverableNumber, 
												deliverableactor, deliverablestatus, deiverableadditionalNotes);
		
		list.add(deliv);
		list.add(deliv);
		list.add(deliv);
		
		return list;
	}
	
	private static Project createProject()
	{
		Project project = new Project();
		
		project.setActors(actors);
		Assert.assertNotNull(project.getActors());
		project.setAdditonalNotes(Project_Description);
		Assert.assertNotNull(project.getAdditonalNotes());
		project.setCreator(creator);
		Assert.assertNotNull(project.getCreator());
		project.setCurrentDeliverablesCompleted(Project_number_deliverables);
		project.setCurrentMilestonesCompleted(Project_number_milestones);
		project.setDeliverables(deliverables);
		Assert.assertNotNull(project.getDeliverables());
		// create events
		//Assert.assertNotNull(project.getEvents());
		project.setExpectedCompletionDate(expectedCompletionDate);
		project.setFinalCompletionDate(finalCompletionDate);
		project.setId(Project_ID);
		project.setMilestones(milestones);
		Assert.assertNotNull(project.getMilestones());
		project.setName(Project_Name);
		project.setNumber_deliverables(Project_number_deliverables);
		project.setNumber_Milestones(Project_number_milestones);
		project.setPublications(publications);
		Assert.assertNotNull(publications);
		project.setStatus(status);
		project.setTotalCompletionRate(0.0f);
		return project;
	}
	
	public static Project projectFactory()
	{
		if (project == null)
			project = createProject();
		
		return project;
	}
	
	public static List<Person> getActors()
	{
		return projectFactory().getActors();
	}
	
	public static List<Deliverable> getDeliverables()
	{
		return projectFactory().getDeliverables();
	}
	
	public static List<Milestone> getMilestones()
	{
		return projectFactory().getMilestones();
	}
	
	public static List<Publication> getPublications()
	{
		return projectFactory().getPublications();
	}

}
